﻿using System;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using VDC.COMMON;

namespace VDC.VONE.ENTITIES
{
    /// <summary>
    /// UserDefaultEN class
    /// </summary>
    public class UserDefaultEN : EntityEN
    {
        /// <summary>
        /// Gets or sets the user default id.
        /// </summary>
        /// <value>
        /// The user default id.
        /// </value>
        public int UserDefaultId { get; set; }

        /// <summary>
        /// Gets or sets the node wf role default id.
        /// </summary>
        /// <value>
        /// The node wf role default id.
        /// </value>
        public int NodeWFRoleDefaultId { get; set; }

        /// <summary>
        /// Gets or sets the user id.
        /// </summary>
        /// <value>
        /// The user id.
        /// </value>
        public int UserId { get; set; }

        /// <summary>
        /// Gets or sets the department id.
        /// </summary>
        /// <value>
        /// The department id.
        /// </value>
        public int DepartmentId { get; set; }

        /// <summary>
        /// Gets or sets the positions id.
        /// </summary>
        /// <value>
        /// The positions id.
        /// </value>
        public int PositionsId { get; set; }

        /// <summary>
        /// Gets NodeWFRoleDefault
        /// </summary>
        public NodeWFRoleDefaultEN NodeWFRoleDefault
        {
            get
            {
                try
                {
                    NodeWFRoleDefaultEN nodeWFRoleDefault = null;
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeFWRoleDefaultGetById, this.NodeWFRoleDefaultId);
                    while (reader.Read())
                    {
                        nodeWFRoleDefault = new NodeWFRoleDefaultEN();

                        if (!reader.IsDBNull(0))
                        {
                            nodeWFRoleDefault.NodeWFRoleDefaultId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            nodeWFRoleDefault.NodeWorkflowRollId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            nodeWFRoleDefault.ProfileTypeId = reader.GetInt32(2);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return nodeWFRoleDefault;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets User
        /// </summary>
        public UserEN User
        {
            get
            {
                try
                {
                    UserEN user = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneUsersGetById, this.UserId);

                    while (reader.Read())
                    {
                        user = new UserEN();

                        if (!reader.IsDBNull(0))
                        {
                            user.UserId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            user.AdministrativeUnitsId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            user.UserName = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            user.FullName = reader.GetString(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            user.Sex = reader.GetBoolean(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            user.BirthDate = reader.GetDateTime(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            user.Email = reader.GetString(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            user.Sms = reader.GetString(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            user.Phone = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            user.Address = reader.GetString(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            user.CreateDate = reader.GetDateTime(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            user.Send = reader.GetString(11);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return user;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets Department
        /// </summary>
        public DepartmentEN Department
        {
            get
            {
                try
                {
                    DepartmentEN department = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneDepartmentGetById, this.DepartmentId);

                    while (reader.Read())
                    {
                        department = new DepartmentEN();

                        if (!reader.IsDBNull(0))
                        {
                            department.DepartmentId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            department.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            department.Name = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            department.Parent = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            department.Order = reader.GetInt32(4);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return department;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets the position.
        /// </summary>
        public PositionEN Position
        {
            get
            {
                try
                {
                    PositionEN position = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOnePositionsGetById, this.PositionsId);

                    while (reader.Read())
                    {
                        position = new PositionEN();

                        if (!reader.IsDBNull(0))
                        {
                            position.PositionsId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            position.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            position.Name = reader.GetString(2);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return position;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}